package com.ktgj.hotel.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.hotel.domain.stations.DicCityBrandVo;
import com.ktgj.hotel.domain.vo.BrandVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.hotel.domain.DicCityBrand;
import com.ktgj.hotel.service.IDicCityBrandService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2021-12-09
 */
@ControllerAdvice
@RestController
@RequestMapping("/cityBrand")
public class DicCityBrandController extends BaseController
{
    @Autowired
    private IDicCityBrandService dicCityBrandService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "hotel:brand:list")
    @GetMapping("/list")
    public TableDataInfo list(DicCityBrand dicCityBrand)
    {
        startPage();
        List<DicCityBrand> list = dicCityBrandService.selectDicCityBrandList(dicCityBrand);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "hotel:brand:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DicCityBrand dicCityBrand) throws IOException
    {
        List<DicCityBrand> list = dicCityBrandService.selectDicCityBrandList(dicCityBrand);
        ExcelUtil<DicCityBrand> util = new ExcelUtil<DicCityBrand>(DicCityBrand.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize(hasPermi = "hotel:brand:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dicCityBrandService.selectDicCityBrandById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "hotel:brand:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DicCityBrand dicCityBrand)
    {
        return toAjax(dicCityBrandService.insertDicCityBrand(dicCityBrand));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "hotel:brand:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DicCityBrand dicCityBrand)
    {
        return toAjax(dicCityBrandService.updateDicCityBrand(dicCityBrand));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "hotel:brand:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dicCityBrandService.deleteDicCityBrandByIds(ids));
    }

    /**
     * 站点
     * */
    @PostMapping("/queryCityIdByBrand")
    public AjaxResult queryCityIdByBrand(@RequestBody Map<String, Object> map) {
        String cityName = null;
        String lng = null;
        String lat = null;
        if (map.get("cityName") != null && !map.get("cityName").equals("")){
            cityName = map.get("cityName").toString();
        }
        else if (map.get("lng") != null && !map.get("lng").equals("") && map.get("lat") != null && !map.get("lat").equals("")){
            lng = map.get("lng").toString();
            lat = map.get("lat").toString();
        }
        else {
            return AjaxResult.error("缺少必要参数");
        }

        List<BrandVo> brandVos;
        try {
            brandVos = dicCityBrandService.queryCityIdByBrand(cityName, lng, lat);
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }
        if (brandVos != null) {
            return AjaxResult.success(brandVos);
        } else {
            return AjaxResult.error("站点查询失败");
        }
    }
}
